/*
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program. If not, see <http://www.gnu.org/licenses/>.
 */
package org.merak.core.web.mvc;

import org.apache.log4j.Logger;
import org.merak.core.Application;
import org.merak.core.configuration.web.mvc.BusinessSettings;
import org.merak.core.configuration.web.mvc.ControlSettings;
import org.merak.core.configuration.web.mvc.SecuritySettings;
import org.merak.core.configuration.web.mvc.ViewSettings;
import org.merak.core.configuration.web.mvc.WebMVC;

public class MVCManager {

	//~ Attributes ///////////////////////////////////////////////////////////////
	//****************************************************************************
	private static WebMVC           settings         = Application.getConfiguration().getWebMVC();
	private static BusinessSettings businessSettings = settings.getControl().getBusiness();
	private static SecuritySettings securitySettings = settings.getControl().getSecurity();
	private static Logger           logger           = Logger.getLogger("MVCManager");

	//~ Static Constructor ///////////////////////////////////////////////////////
	//****************************************************************************
	static {

		// Set a default Business Package if no one has been specified
		if ( businessSettings.getPackage() == null ) {
			businessSettings.setPackage(MVCManager.class.getPackage().getName() + ".business");
			logger.warn("Using default Business Package: " + businessSettings.getPackage());
		}

		// if business parameter isn't configured, use a default one
		if ( businessSettings.getParameter() == null ) {
			businessSettings.setParameter("business");
			logger.info("Using default Bussiness Parameter: business");
		}

		// if view package isn't configured, use a default one
		ViewSettings viewSettings = settings.getView();
		if ( viewSettings.getPackage() == null ) {
			viewSettings.setPackage(MVCManager.class.getPackage().getName() + ".view");
			logger.warn("Using default View Package: " + viewSettings.getPackage());
		}

	}

	//~ Methods //////////////////////////////////////////////////////////////////
	//****************************************************************************
	public static String getBusinessParameter() {
		return businessSettings.getParameter();
	}
	//****************************************************************************
	public static String getBusinessPackage() {
		return businessSettings.getPackage();
	}
	//****************************************************************************
	public static String getSessionAccountKey() {
		return securitySettings.getSessionAccountKey();
	}
	//****************************************************************************
	public static WebMVC getSettings() {
		return settings;
	}
	//****************************************************************************
	public static ControlSettings getControl() {
		return settings.getControl();
	}
	//****************************************************************************
	public static ViewSettings getView() {
		return settings.getView();
	}
	//****************************************************************************

}
